package com.zmn.oms.admin.common;

import com.alibaba.nacos.api.config.annotation.NacosValue;
import com.google.common.collect.Lists;
import org.apache.commons.lang.StringUtils;

import java.util.List;

/**
 * 类描述:
 *
 * @author liuying
 * @date 2022/06/04 23:41
 */
public class BaiduAk {
    private long webAkCount = 0;
    private long addOrderWebAkCount = 0;

    // 主AK Lh3Dt8AlQaStSKDldLdG0a5q
    public String PRIMARY_WEB_AKS = "Lh3Dt8AlQaStSKDldLdG0a5q";
    // 录单专用 1659aM4Ikyrl06XRAuwIVYSuBzjarHGr
    public List<String> ADD_ORDER_WEB_AKS = Lists.newArrayList(
            "1659aM4Ikyrl06XRAuwIVYSuBzjarHGr",
            "AzuiLZz7tGgLb8abNIVZYd8zr78avMw2"
    );
    // 其它使用
    public List<String> OTHERS_WEB_AKS = Lists.newArrayList();

//    // 录单专用 1659aM4Ikyrl06XRAuwIVYSuBzjarHGr
//    @NacosValue(value = "${baidu.ak.web.addOrder:}", autoRefreshed = true)
//    public void setAddOrderWebAks(List<String> aks){
//        ADD_ORDER_WEB_AKS = aks;
//    }
//
//    // 主AK Lh3Dt8AlQaStSKDldLdG0a5q
//    @NacosValue(value = "${baidu.ak.web.primary:}", autoRefreshed = true)
//    public void setPrimaryWebAks(String ak){
//        PRIMARY_WEB_AKS = ak;
//    }
//
//    // 其它使用
//    @NacosValue(value = "${baidu.ak.web.others:}", autoRefreshed = true)
//    public void setOthersWebAks(List<String> aks){
//        OTHERS_WEB_AKS = aks;
//    }

//    "o3s1Xsxh7RGhKIGDCD0ruQ7pUTAWHBXD",
//    "G1Zl6aksZvhig9rv57trqQpPEtRWFYyx",
//    "42M0ERTjXNIsXYEdVjKIEXQnvgBvWAtP",
//    "ONiYp5fblpKbXiOuuSyRvWNIAkeiGe7x",
//    "7tQVF9go5MayoaUrRhdTGvv2s16hBHRM",
//    "dlHU41UgpHE4iALnVpwawatx2W2m3u3s",
//    "jz9sqbRWEyaVpe37V1yCpii0BM3RKXb7",
//    "SrTH2vkwUIDaG9OWYEXC5IdX2PcxzM9V"

    /**
     * 获取百度 ak， 仅限页面上使用
     *
     * @return
     */
    public String getWebAk() {
        if (StringUtils.isNotBlank(PRIMARY_WEB_AKS)) {
            return PRIMARY_WEB_AKS;
        }

        webAkCount++;
        if (webAkCount > 100000) {
            webAkCount = 1;
        }
        int size = OTHERS_WEB_AKS.size();
        int index = (int) webAkCount % size;
        String webAk = OTHERS_WEB_AKS.get(index);
        return webAk;
    }



    /**
     * 获取百度 ak， 仅限页面上使用
     *
     * @return
     */
    public String getAddOrderWebAk() {
        addOrderWebAkCount++;
        if (addOrderWebAkCount > 100000) {
            addOrderWebAkCount = 1;
        }
        int size = ADD_ORDER_WEB_AKS.size();
        int index = (int) addOrderWebAkCount % size;
        String webAk = ADD_ORDER_WEB_AKS.get(index);
        return webAk;
    }

    public static void main(String[] args) {
        BaiduAk baiduAk = new BaiduAk();

        System.out.println(baiduAk.getAddOrderWebAk());
        System.out.println(baiduAk.getAddOrderWebAk());
        System.out.println(baiduAk.getAddOrderWebAk());
        System.out.println(baiduAk.getAddOrderWebAk());
    }
}
